/**   
* @Package com.app.open.sys.application.web 
*/
package com.wlyy.bcwlw.sys.application.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wlyy.bcwlw.base.BaseController;
import com.wlyy.bcwlw.sys.application.dao.ApplicationDAO;
import com.wlyy.bcwlw.sys.application.entity.ApplicationDTO;
import com.wlyy.bcwlw.sys.application.service.ApplicationService;
import com.wlyy.bcwlw.sys.menu.dao.ModuleDAO;

/**
 * @ClassName. SysApplicationController
 * @Description. TODO
 * @author zhangyang
 * @date 2015年8月8日 上午10:53:00
 * @version V1.0
 */
@RemoteProxy
@Controller
@RequestMapping("/sys/app")
public class SysApplicationController extends BaseController{
	
	@Autowired
	private ApplicationDAO applicationDAO;
	@Autowired
	private ApplicationService applicationService;
	@Autowired
	private ModuleDAO moduleDAO;
	
	@RequestMapping("/view")
	public String appListView(HttpServletRequest request, HttpServletResponse response) throws Exception{
		return "sys/application/app-list";
	}
	
	@RequestMapping("/list")
	public String appList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		int curPage = getPageNum(request);
		int limit = getInternal(request);
		
		List<ApplicationDTO> list = applicationDAO.queryListByCriteria(null, " scrq desc ", null, null);
		
		int count = list.size();
		
		processJsonData4Grid(request, response, limit, curPage, count, list);
		
		return null;
	}
	
	@RequestMapping("/checkNameISExist")
	public String checkNameISExist(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String appName = get(request,"appName");
		String appId = get(request,"appId");
		String str ="true";
		ApplicationDTO applicationDTO = new ApplicationDTO();
		applicationDTO.setAppName(appName);
		int count = applicationDAO.count(applicationDTO);
		if(count >0){
			str="false";
		}
		if(StringUtils.isNotEmpty(appId)){
			applicationDTO = applicationDAO.findById(appId);
			if(applicationDTO.getAppName().equals(appName)){
				str="true";
			}
		}
		sendMessage(response, str);
		return null;
	}
	
	
	public boolean saveApplicationInfo(ApplicationDTO applicationDTO){
		
		return applicationService.saveApplicationInfo(applicationDTO);
	}
	
	public boolean removeAppByAppId(String appId){
		return applicationService.removeAppByAppId(appId);
	}

}
